aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/fund/[id]/+page.server.ts
blob: 4f1891335aa0cc2b4612444bfaaa9040e5d304d0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { redirect } from "@sveltejs/kit";
import { auth, get, post } from "$lib/utils";
import Qr from "qrcode-base64";

export const load = async ({ params: { id }, url }) => {
	const { amount, payments } = await get(`/fund/${id}`);

	const src = Qr.drawImg(url.href, { size: 300 });
	return { amount, payments, src };
};

export const actions = {
	default: async ({ cookies, locals, params }) => {
		const { user } = locals;

		if (user) {
			await post("/redeem", params, auth(cookies));
			redirect(307, "/payments");
		}

		redirect(307, "/register");
	},
};